/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.EditPanes.Filter;

import B3D_Elements.B3D_Filters.B3D_BasicSSAO;
import GUI.Components.BTextField;
import GUI.EditPanes.EditTaskPane;
import General.CurrentData;
import com.shaderblow.filter.basicssao.BasicSSAO;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.Callable;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import other.ObjectToElementConverter;
import se.datadosen.component.RiverLayout;

/**
 *
 * @author David
 */
public class BasicSSAOTaskPane extends EditTaskPane
{

    private BTextField biasField, detailBiasField, detailIntensityField, detailSampleRadiusField, detailScaleField, falloffRateField,
            falloffStartDistanceField, intensityField, sampleRadiusField, scaleField;
    private JCheckBox smoothMoreCheckBox, useAOCheckBox, useOnlyAOCheckBox, useDetailPassCheckBox, useDistanceFalloffCheckBox, useSmoothingCheckBox;

    public BasicSSAOTaskPane(final BasicSSAO basicSSAO)
    {
        biasField = new BTextField("Float", Float.toString(basicSSAO.getBias()));
        detailBiasField = new BTextField("Float", Float.toString(basicSSAO.getDetailBias()));
        detailIntensityField = new BTextField("Float", Float.toString(basicSSAO.getDetailIntensity()));
        detailSampleRadiusField = new BTextField("Float", Float.toString(basicSSAO.getDetailSampleRadius()));
        detailScaleField = new BTextField("Float", Float.toString(basicSSAO.getDetailScale()));
        falloffRateField = new BTextField("Float", Float.toString(basicSSAO.getFalloffRate()));
        falloffStartDistanceField = new BTextField("Float", Float.toString(basicSSAO.getFalloffStartDistance()));
        intensityField = new BTextField("Float", Float.toString(basicSSAO.getIntensity()));
        sampleRadiusField = new BTextField("Float", Float.toString(basicSSAO.getSampleRadius()));
        scaleField = new BTextField("Float", Float.toString(basicSSAO.getScale()));
        smoothMoreCheckBox = new JCheckBox("", basicSSAO.isSmoothMore());
        useAOCheckBox = new JCheckBox("", basicSSAO.isUseAo());
        useOnlyAOCheckBox = new JCheckBox("", basicSSAO.isUseOnlyAo());
        useDetailPassCheckBox = new JCheckBox("", basicSSAO.getUseDetailPass());
        useDistanceFalloffCheckBox = new JCheckBox("", basicSSAO.getUseDistanceFalloff());
        useSmoothingCheckBox = new JCheckBox("", basicSSAO.isUseSmoothing());
        smoothMoreCheckBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {

                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        basicSSAO.setSmoothMore(smoothMoreCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        useAOCheckBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {

                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        basicSSAO.setUseAo(useAOCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        useOnlyAOCheckBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {

                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        basicSSAO.setUseOnlyAo(useOnlyAOCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        useDetailPassCheckBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {

                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        basicSSAO.setUseDetailPass(useDetailPassCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        useDistanceFalloffCheckBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {

                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        basicSSAO.setUseDistanceFalloff(useDistanceFalloffCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        useSmoothingCheckBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {

                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        basicSSAO.setUseSmoothing(useSmoothingCheckBox.isSelected());
                        return null;
                    }
                });
            }
        });
        applyButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                {
                    public Void call() throws Exception
                    {
                        CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().removeFilter(
                                basicSSAO);
                        CurrentData.getEditorWindow().getB3DApplication().getElementList().removeByObject(basicSSAO);
                        CurrentData.getEditorWindow().getB3DApplication().setSelectedElement(null, null);
                        BasicSSAO newBasicSSAO = new BasicSSAO();
                        newBasicSSAO.setBias(Float.parseFloat(biasField.getText()));
                        newBasicSSAO.setDetailBias(Float.parseFloat(detailBiasField.getText()));
                        newBasicSSAO.setDetailIntensity(Float.parseFloat(detailIntensityField.getText()));
                        newBasicSSAO.setDetailSampleRadius(Float.parseFloat(detailSampleRadiusField.getText()));
                        newBasicSSAO.setDetailScale(Float.parseFloat(detailScaleField.getText()));
                        newBasicSSAO.setIntensity(Float.parseFloat(intensityField.getText()));
                        newBasicSSAO.setSampleRadius(Float.parseFloat(sampleRadiusField.getText()));
                        newBasicSSAO.setScale(Float.parseFloat(scaleField.getText()));
                        newBasicSSAO.setSmoothMore(smoothMoreCheckBox.isSelected());
                        newBasicSSAO.setUseAo(useAOCheckBox.isSelected());
                        newBasicSSAO.setUseDetailPass(useDetailPassCheckBox.isSelected());
                        newBasicSSAO.setUseDistanceFalloff(useDistanceFalloffCheckBox.isSelected());
                        newBasicSSAO.setUseOnlyAo(useOnlyAOCheckBox.isSelected());
                        newBasicSSAO.setUseSmoothing(useSmoothingCheckBox.isSelected());
                        newBasicSSAO.setFalloffRate(Float.parseFloat(falloffRateField.getText()));
                        newBasicSSAO.setFalloffStartDistance(Float.parseFloat(falloffStartDistanceField.getText()));
                        CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(
                                newBasicSSAO);
                        B3D_BasicSSAO b3D_BasicSSAO = ObjectToElementConverter.convertBasicSSAO(newBasicSSAO);
                        CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(newBasicSSAO, b3D_BasicSSAO);
                        CurrentData.getEditorWindow().getB3DApplication().setSelectedElement(b3D_BasicSSAO.getID());
                        CurrentData.getEditorWindow().getTree().sync();
                        CurrentData.getEditorWindow().getEditPane().arrange(true);
                        return null;
                    }
                });
            }
        });
        taskPane.setLayout(new RiverLayout());
        taskPane.add("left", new JLabel("Bias:"));
        taskPane.add("tab hfill", biasField);
        taskPane.add("br left", new JLabel("Detail Bias:"));
        taskPane.add("tab hfill", detailBiasField);
        taskPane.add("br left", new JLabel("Detail Intensity:"));
        taskPane.add("tab hfill", detailIntensityField);
        taskPane.add("br left", new JLabel("Detail Sample Radius:"));
        taskPane.add("tab hfill", detailSampleRadiusField);
        taskPane.add("br left", new JLabel("Detail Scale:"));
        taskPane.add("tab hfill", detailScaleField);
        taskPane.add("br left", new JLabel("Falloff Rate:"));
        taskPane.add("tab hfill", falloffRateField);
        taskPane.add("br left", new JLabel("Falloff Start Distance:"));
        taskPane.add("tab hfill", falloffStartDistanceField);
        taskPane.add("br left", new JLabel("Intensity:"));
        taskPane.add("tab hfill", intensityField);
        taskPane.add("br left", new JLabel("Sample Radius:"));
        taskPane.add("tab hfill", sampleRadiusField);
        taskPane.add("br left", new JLabel("Scale:"));
        taskPane.add("tab hfill", scaleField);
        taskPane.add("br left", new JLabel("Smooth More:"));
        taskPane.add("tab hfill", smoothMoreCheckBox);
        taskPane.add("br left", new JLabel("Use AO:"));
        taskPane.add("tab hfill", useAOCheckBox);
        taskPane.add("br left", new JLabel("Use only AO:"));
        taskPane.add("tab hfill", useOnlyAOCheckBox);
        taskPane.add("br left", new JLabel("Use Detail Pass:"));
        taskPane.add("tab hfill", useDetailPassCheckBox);
        taskPane.add("br left", new JLabel("Use Distance Falloff:"));
        taskPane.add("tab hfill", useDistanceFalloffCheckBox);
        taskPane.add("br left", new JLabel("Use Smoothing:"));
        taskPane.add("tab hfill", useSmoothingCheckBox);
        taskPane.add("br right", applyButton);
        add(taskPane, BorderLayout.CENTER);
    }
}
